﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemySpawnTrigger : MonoBehaviour 
{

	public GameObject enemyObject;
	public int enemyAmount;
	public bool onlyOnce;


	void OnCollisionEnter2D(Collision2D collider)
	{
		if (collider.gameObject.tag == "Player")
		{
			if(onlyOnce == true)
			{
				
				for(int i = 0; i < enemyAmount; i++)
				{
					Instantiate(enemyObject, (Vector2)transform.position + 3 * Random.insideUnitCircle, Quaternion.identity);
				}
				gameObject.GetComponent<Collider2D>().enabled = false;
			}
			else
			{
				for(int i = 0; i < enemyAmount; i++)
				{
					Instantiate(enemyObject, (Vector2)transform.position + 3 * Random.insideUnitCircle, Quaternion.identity);
				}
			}
				

		}
	}


}
